package com.wsh.lab.conf;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

/**
 * @author wsh
 * @date 2021-11-25 16:29
 */
@Configuration
@PropertySource(value = "classpath:jdbc-mysql.properties")
@Component
public class JdbcConf {
    public static String jdbcDriver;
    public static String jdbcUrl;
    public static String jdbcUser;
    public static String jdbcPassword;

    @Bean(name = "jdbcConfProperties")
    public static JdbcConf getConf(@Value("${jdbc.driver}") String jdbcDriver,
                            @Value("${jdbc.url}") String jdbcUrl,
                            @Value("${jdbc.user}") String jdbcUser,
                            @Value("${jdbc.password}") String jdbcPassword) {
        JdbcConf.jdbcDriver = jdbcDriver;
        JdbcConf.jdbcUrl = jdbcUrl;
        JdbcConf.jdbcUser = jdbcUser;
        JdbcConf.jdbcPassword = jdbcPassword;
        return new JdbcConf();
    }

    // 这样也行，但也不够优雅
//    @Bean(name = "jdbcDriver")
//    public static String setJdbcDriver(@Value("${jdbc.driver}") String jdbcDriver) {
//        JdbcConf.jdbcDriver = jdbcDriver;
//        return JdbcConf.jdbcDriver;
//    }
//
//    @Bean(name = "jdbcUrl")
//    public static String setJdbcUrl(@Value("${jdbc.url}") String jdbcUrl) {
//        JdbcConf.jdbcUrl = jdbcUrl;
//        return JdbcConf.jdbcUrl;
//    }
//
//    @Bean(name = "jdbcUser")
//    public static String setJdbcUser(@Value("${jdbc.user}") String jdbcUser) {
//        JdbcConf.jdbcUser = jdbcUser;
//        return JdbcConf.jdbcUser;
//    }
//
////    @Bean(name = "jdbcPassword")
//    public static String setJdbcPassword(@Value("${jdbc.password}") String jdbcPassword) {
//        JdbcConf.jdbcPassword = jdbcPassword;
//        return JdbcConf.jdbcPassword;
//    }
}
